public
class MyThread extends Thread
{
	private int whichThread;
	private int delay;
	private static Account account;;
	public MyThread(int whichThread, int delay)
	{
		super();
		this.delay = delay;
		this.whichThread = whichThread;
	}
	public void run()
	{
		switch(whichThread){
			case 1: thread1();break;
			case 2: thread2();break;
			case 3: thread3();break;
		}
	}
	public static void main(String args[])
	{
		account = new Account();
		new MyThread(1, 1).start();
		new MyThread(2, 4).start();
		new MyThread(3, 0).start();
	}
	public static synchronized void updateAccount()
	{
		int temp = account.value;
		account.value = temp + 1;
	}
	public void thread1()
	{
		for(int i = 0; i < 10; i++){
			updateAccount();
			System.out.println(getName() + " " + account.value);
			try{
				sleep(delay);
			}
			catch(InterruptedException e){
			}
		}
	}
	public void thread2()
	{
		for(int i = 0; i < 10; i++){
			updateAccount();
			System.out.println(getName() + " " + account.value);
			try{
				sleep(delay);
			}
			catch(InterruptedException e){
			}
		}
	}
	public synchronized void thread3()
	{
		try{
			wait(1000);
		}
		catch(InterruptedException e){
			System.out.println(e);
		}
		System.out.println(getName() + " " + account.value);
	}
}
